package HLUserControl.HLHomepage.HLPageMain;

import javax.microedition.lcdui.Image;

import HLLib.base.HLGraphics;
import HLLib.base.HLGraphics_H;
import HLLib.base.HLImage;
import HLLib.base.HLMath;
import HLLib.control.HLPanel;
import HLLib.control.HLTextPage;
import HLLib.handfere.HLIOManager;

public class HLMoodPanel extends HLPanel {
    public static final int TEXT_OFFSET_Y = 8;

    HLTextPage mood;

    Image back[] = HLIOManager.LoadImages1("/mood.pak");

    public HLMoodPanel(String text, String defaultText) {

        this.width = (short) HLLib.base.HLScreen.width;
        int startX = HLMath.GetPosAdjustableH(back[0].getWidth(), 0, width, HCENTER);
//        mood = new HLTextPage(HLLib.base.HLScreen.width - startX * 2 - 6, 0, 0xff646567);
        // mood = HLTextPage.GetTextPageByLines(HLLib.base.HLScreen.width -
        // TEXT_OFFSET_X * 2, 3, 0xff646567 ,0);
        if (text == null || text.trim().equals("") || text.trim() == null || text.length() == 0) {
            text = defaultText;// ;
            mood.SetText1(text);
            height = mood.height + TEXT_OFFSET_Y * 2;
        } else {
            mood.SetText1(text);
            height = mood.height + TEXT_OFFSET_Y * 2;
        }
    }

    public void SetText(String text) {
        height -= mood.height;
        mood.SetText1(text);
        height += mood.height;
    }

    public void Logic() {
        super.Logic();
    }

    public void Refresh() {
        super.Refresh();
    }

    public void Render(HLGraphics g) {
        int screenX = GetScreenX();
        int screenY = GetScreenY();
        super.Render(g);
        if (mood != null) {
            int startX = HLMath.GetPosAdjustableH(back[0].getWidth(), 0, width, HCENTER);
            int startY = screenY - TEXT_OFFSET_Y;
            g.DrawImageAdjustable(new HLImage(back[0]), screenX, startY, width, height, HLGraphics_H.TRANS_NONE, HCENTER_TOP);
            int midHeight = mood.height - back[0].getHeight() - back[2].getHeight() + TEXT_OFFSET_Y + 7;
            if (midHeight <= 0) {
                midHeight = back[1].getHeight();
            }
            startY += back[0].getHeight();
            g.DrawImageFillRect(new HLImage(back[1]), startX, startY, back[1].getWidth(), midHeight, HLGraphics_H.TRANS_NONE);
            startY += midHeight;
            g.DrawImageAdjustable(new HLImage(back[2]), screenX, startY, width, height, HLGraphics_H.TRANS_NONE, HCENTER_TOP);
            mood.Render(g, screenX + startX + 3, screenY + 4);
        }
    }

}
